package com.secret.chain.secretchain.service.impl;

import com.secret.chain.secretchain.domain.entity.Answer;
import com.secret.chain.secretchain.mapper.AnswerMapper;
import com.secret.chain.secretchain.result.Result;
import com.secret.chain.secretchain.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    private AnswerMapper answerMapper;
    @Override
    public Result queryByProblemId(Integer id) {
        Answer answer = answerMapper.queryByProblemId(id);
        return Result.success(answer);
    }

    @Override
    public Result save(Answer answer) {
        LocalDateTime now = LocalDateTime.now();
        answer.setCreateTime(now);
        answer.setUpdateTime(now);
        answer.setStatus(1);
        answerMapper.insert(answer);
        return Result.success();
    }

    @Override
    public Result delete(Integer id) {
        answerMapper.delete(id);
        return Result.success();
    }

    @Override
    public Result update(Answer answer) {
        LocalDateTime now = LocalDateTime.now();
        answer.setUpdateTime(now);
        answerMapper.update(answer);
        return Result.success();
    }
}
